def primes():
    yield 2
    seq = _seq_init()
    while True:
        n = next(seq)
        yield n
        seq = filter(lambda x: x % n > 0, seq)

def _seq_init():
    x = 3
    while True:
        yield x
        x = x + 2

for x in primes():
    print(x)
    if x > 1000:
        break
